/**
 * @module 写入数据
 */

const path = require('path');
const fs = require('fs');
const util = require('util');
const rootPath = process.cwd();
const writeFile = util.promisify(fs.writeFile);

async function writeData(fileName='', data){

   let filePath = path.resolve(path.join(rootPath, `./db/${fileName}`))
   try{
        return writeFile(filePath, JSON.stringify(data, null, 2), {encoding: 'utf-8'})
   }catch(e){
        console.log(e)
   }

}

module.exports = writeData;